package testLayer;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import modelLayer.Product;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import dbLayer.DBProduct;

public class DBProductTest {

	private int 	  id_fail = 0,
					  id_success = 1;
	private String	  name_fail = "h�rdb�nd",
					  name_success = "armb�nd";
	private DBProduct dbProduct;
	
	@Before
	public void setUp() throws Exception {	
		
		this.dbProduct = new DBProduct();
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testFindByIDSuccess() {

		assertTrue(this.dbProduct.findProductID(this.id_success) != null);
		
	}
	
	@Test
	public void testFindByIDFail() {
		
		assertTrue(this.dbProduct.findProductID(this.id_fail) == null);
		
	}
	
	@Test
	public void testFindByNameSuccess() {
		
		List<Product> products = new ArrayList<>();
		products = this.dbProduct.findProductName(this.name_success);
		for (Product p : products) {
			System.out.println(p.getName() + ", " + p.getProductID());
		}
		assertTrue(this.dbProduct.findProductName(this.name_success) != null);
		
	}
	
	@Test
	public void testFindByNameFail() {
		
		List<Product> products = new ArrayList<>();
		products = this.dbProduct.findProductName(this.name_fail);
		for (Product p : products) {
			System.out.println(p.getName() + ", " + p.getProductID());
		}
		assertTrue(this.dbProduct.findProductName(this.name_fail) == null);
		
	}

}
